package com.ichina.chat.action;

import java.util.List;

import javax.annotation.Resource;

import com.ichina.chat.dao.RobotDao;
import com.ichina.chat.dao.TypeDao;
import com.ichina.chat.vo.Robot;
import com.ichina.chat.vo.Type;
import com.opensymphony.xwork2.ActionSupport;

public class RobotAction extends ActionSupport {

	@Resource private RobotDao robotDao;
	@Resource private TypeDao typeDao;
	private String result = "error";
	private String user;
	private String question;
	private String answer;
	private Type type;
	private	String typeid;
	private Robot robot;
	private List<Type> typeList;
	private List<Robot> robotList;
	public String login() {
		System.err.println(user);
		if (!"".equals(user) && user != null) {
			result = "ok";
		}
		return result;
	}

	public String find() {
		try {
			try{
				question = java.net.URLDecoder.decode(question,"UTF-8");
			}catch(Exception e){e.printStackTrace();}
			List<Robot> list = robotDao.getAnswer(question,Integer.parseInt(typeid));
			int a = 0;
			result = "answer";
			answer = "我还不晓得你问的什么";
			for(Robot robot : list){
				answer = robot.getContext();
				if(a == 0){
					return result;
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	public String finds(){
		try{
			try{
				question = java.net.URLDecoder.decode(question,"UTF-8");
			}catch(Exception e){e.printStackTrace();}
			robotList = robotDao.getAnswer(question, Integer.parseInt(typeid));
			result = "answers";
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}
	
	public String findType(){
		try {
			typeList = typeDao.getAll();
			result = "typeSeccuss";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getAnswer() {
		return answer;
	}

	public void setAnswer(String answer) {
		this.answer = answer;
	}

	public String getQuestion() {
		return question;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public Robot getRobot() {
		return robot;
	}

	public void setRobot(Robot robot) {
		this.robot = robot;
	}

	public List<Type> getTypeList() {
		return typeList;
	}

	public void setTypeList(List<Type> typeList) {
		this.typeList = typeList;
	}

	public List<Robot> getRobotList() {
		return robotList;
	}

	public void setRobotList(List<Robot> robotList) {
		this.robotList = robotList;
	}

	public String getTypeid() {
		return typeid;
	}

	public void setTypeid(String typeid) {
		this.typeid = typeid;
	}

}
